function S = selectRules(Q, project_id,subject_id)

%Takes the above varialbles and creates a S3QL insert statement for an
%rules. Q is a struct as described in s3db_read with url and key
%   subject_id: OPTIONAL: notes is optional

%ROmesh Stanislaus May 2009

switch nargin
    case 2
        if isnumeric(project_id)
            project_id = num2str(project_id);
        end
        %display(Q); display(collection_id)
        S1 = ['<S3QL><select>*</select><from>rules</from><where><project_id>',...
            project_id,'</project_id></where></S3QL>'];
    case 3
        %display(Q);display(collection_id);display(notes)
        if isnumeric(subject_id)
            subject_id = num2str(subject_id);
        end
        S1 = ['<S3QL><select>*</select><from>items</from><where><collection_id>',...
            collection_id,'</collection_id><notes>',notes,'</notes></where></S3QL>'];
    otherwise
        error('ddddd')
end

Q.X = S1;

[D1,Q]=s3db_read(Q); % -2
%D1 will be a struct which has among other item_id wich can be referenced
%by D1(1).item_id
%pause(3);
S = D1;